package bark;

import doors.DogDoor;
import java.util.Iterator;
import java.util.LinkedList;

public class BarkRecognizer {

  private DogDoor door;

  public BarkRecognizer(DogDoor door) {
    this.door = door;
  }

  public void recognize(Bark bark) {
    System.out.println("Usłyszano " + bark.getSound());
    LinkedList allowdedBarks = door.getAllowdedBarks();
    for (Iterator i = allowdedBarks.iterator(); i.hasNext(); ) {
        Bark allowdedBark = (Bark)i.next();
        if (allowdedBark.equals(bark)) {
            door.open();
            return;
        }
    }
  }
}